/*
 * Copyright (C) 2006 Roman Krashanitsa
 *
 * @author Roman Krashanitsa
 *
 * This file is part of paparazzi.
 *
 * paparazzi is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * paparazzi is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with paparazzi; see the file COPYING.  If not, write to
 * the Free Software Foundation, 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA. 
 *
 */


package pprz.data_components;

import java.util.Vector;


public class Message {
	protected short _class;
	protected String _name;
	protected short _ac;
	protected int _id;
	protected byte[] _payload; 
	protected double _time;
	protected Aircraft ac;
	
	protected Vector<Long[]> fields; 
	
	public Message(){
		this.fields=new Vector<Long[]>();
		}
	
	public Message(short c, double time, byte[] payload)
			{
				this._class=c;
				this._id=payload[1];
				this._ac=payload[0];
				this._time=time;
				this.fields=new Vector<Long[]>(); 
				this._payload = new byte[payload.length];
			    System.arraycopy(payload,0,this._payload,0,payload.length );
			}
	
	public Message(short c, double time, Aircraft payload)
	{
		this._class=c;
		this._time=time;
		this.ac=payload;
		this.fields=new Vector<Long[]>();
	}
	
	// set finite precision long FP-encoded field
	public void setField(int i,Long[] val)
	{
		fields.set(i, val);
	}
	//set fields array length
	public void setFieldsLength(int n)
	{
		fields.setSize(n);
	}
	
	// returns an array of finite precision long FP-encoded fields	
	public Vector<Long[]> getFields() {return fields;}
	
	public void setPayload(Aircraft payload)
	{
		this.ac=payload;
	}
	
	public void setPayload(byte[] payload)
	{
		this._payload=payload;
	    //System.arraycopy(payload,0,this._payload,0,payload.length );
//		this._id=payload[1];
//		this._ac=payload[0];	    
	}
	
	public void setId(int id) {this._id=id;}
	public void setClass(short c) {this._class=c;}
	public void setTime(double t) {this._time=t;}
	
	public int msgClass(){return this._class;}
	public int id(){return this._id;}
	public String name(){return _name;}
	public double time(){return _time;}
	public short ac() {return _ac;}
	public byte[] payload(){return _payload;}
	
	public Aircraft acRec(){return ac;}
}
